package edu.pku.sei.autounit.generator;

import java.util.Iterator;

import edu.pku.sei.autounit.core.Variable;
import edu.pku.sei.autounit.core.VariableFactory;
import edu.pku.sei.autounit.core.VariableGenerator;
import edu.pku.sei.autounit.filter.Filter;
import edu.pku.sei.autounit.reflect.Class;
import edu.pku.sei.autounit.reflect.Constructor;
import edu.pku.sei.autounit.reflect.Type;
import edu.pku.sei.autounit.util.NameFactory;

public class NonInstClassGenerator implements VariableGenerator{
	
	public Variable generate(Type type,String name,VariableFactory vf,NameFactory nf) {
		if(!(type instanceof Class))
			return null;
		Class c = (Class)type;
		if(!c.canInstantiation()){
			Iterator<Class> it = c.getSubClasses();
			while(it.hasNext()){
				Class clas = it.next();
				if(clas.canInstantiation()){
					Constructor constructor = null;
					int min = 100;
					for(Constructor con:clas.getPublicConstructors()){
						if(con.getParameters().length<min){
							min = con.getParameters().length;
							constructor = con;
							if(min == 0)
								break;
						}
					}
					return new ConstructorInvoke(type,name,constructor,vf,nf);
				}
			}
		}
		return null;
	}
	
	
	public Variable generate(Type type, String name, Filter fliter,
			VariableFactory vf, NameFactory nf) {
		// TODO Auto-generated method stub
		return null;
	}

}
